package com.example.controller;

import com.example.entity.User;
import com.example.mapper.LeaderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/leaders")
public class LeaderController {

    @Autowired
    private LeaderMapper leaderMapper;

    @GetMapping
    public Map<String, Object> getLeaders() {
        Map<String, Object> result = new HashMap<>();
        try {
            List<User> leaders = leaderMapper.getLeaders();
            result.put("code", "200");
            result.put("msg", "获取负责人列表成功");
            result.put("data", leaders);
        } catch (Exception e) {
            result.put("code", "500");
            result.put("msg", "获取负责人列表失败: " + e.getMessage());
        }
        return result;
    }
    
    @GetMapping("/byGroup")
    public Map<String, Object> getLeadersByGroup(@RequestParam Integer groupId) {
        Map<String, Object> result = new HashMap<>();
        try {
            List<User> leaders = leaderMapper.getLeadersByGroup(groupId);
            result.put("code", "200");
            result.put("msg", "获取小组负责人列表成功");
            result.put("data", leaders);
        } catch (Exception e) {
            result.put("code", "500");
            result.put("msg", "获取小组负责人列表失败: " + e.getMessage());
        }
        return result;
    }
}